package com.oracle.controller;

import com.oracle.news.service.api.NewsServiceApi;
import com.oracle.pojo.News;
import com.oracle.pojo.dto.SearchNewsDTO;
import com.oracle.search.service.api.SearchServiceApi;
import com.oracle.vo.PageVo;
import com.oracle.vo.R;
import com.oracle.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/member/news")
public class NewsController {

    @Autowired(required = false)
    private SearchServiceApi searchServiceApi;
    @Autowired(required = false)
    private NewsServiceApi newsServiceApi;

    @RequestMapping("/search")

    public R searchNewsIndex(@RequestBody SearchNewsDTO searchNewsDTO){
        System.out.println(searchNewsDTO);
        ResultEntity<PageVo<News>> resultEntity = this.searchServiceApi.getNewsBySearch(searchNewsDTO);
        return new R(resultEntity.getCode(),resultEntity.getMsg(),resultEntity.getData());
    }

    @RequestMapping("/newsInfo")
    public R getNewsInfo(Integer id){
        ResultEntity<News> resultEntity = this.newsServiceApi.getNewsInfoById(id);
        return new R(resultEntity.getCode(),resultEntity.getMsg(),resultEntity.getData());
    }


}
